package com.iflytek.sbd.demo.springflowtest;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.Iterator;

/**
 * @program: springbootdemo
 * @description:
 * @author: 陈英俊
 * @create: 2021-12-23 09:51
 */
@Component
@ConditionalOnProperty(
        prefix = "sbd",
        name = {"logPrint.open"},
        havingValue = "true"
)
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
       System.out.println("执行   BeanFactoryPostProcessor.postProcessBeanFactory的实现(MyBeanFactoryPostProcessor)");
//        BeanDefinition apple = beanFactory.getBeanDefinition("apple");
//        if (apple.getFactoryMethodName().equals("apple")) {
//            apple.setAutowireCandidate(false);//不允许该Bean类型自动装配,说是可以根据名称装配,但是我测试根据名称注入失败
//        }
       // BeanDefinition deepClone = beanFactory.getBeanDefinition("deepClone");
//        Iterator<String> iterator = beanFactory.getBeanNamesIterator();
//        while (iterator.hasNext()){
//            String next = iterator.next();
//            System.out.println(next);
//        }
    }
}
